type ClassNameArg =
  | string
  | number
  | undefined
  | boolean
  | ClassNameDict
  | ClassNameArgArray;

type ClassNameDict = {
  [key in "string" | number]: string | number | boolean;
};

type ClassNameArgArray = ClassNameArg[];
export default function classNames(...args: ClassNameArg[]): string {
  const clazz = [];

  for (const arg of args) {
    if (
      typeof arg === "string" ||
      typeof arg === "number" ||
      typeof arg === "bigint"
    ) {
      clazz.push(arg.toString());
    } else if (Array.isArray(arg)) {
      clazz.push(classNames(arg));
    } else if (typeof arg === "object") {
      // 如果是对象，遍历属性
      for (const key in arg) {
        if (Object.prototype.hasOwnProperty.call(arg, key) && arg[key]) {
          clazz.push(key);
        }
      }
    }
  }

  return clazz.filter(Boolean).join(" ");
}
